<html>
<head><meta charset="utf-8"><title>Auto-insert matching braces · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html">Auto-insert matching braces</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220059460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert%20matching%20braces/near/220059460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html#220059460">(Dec 15 2020 at 23:37)</a>:</h4>
<p>VS Code does not auto-close braces in use statements, which leads to loads of parse errors when going from <code>use the::Thing;</code> to <code>use the::{Thing;</code>.</p>
<p>Is there a way for rust-analyzer to do better here, by automatically closing the use item, or does LSP not support something like that?</p>



<a name="220060301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert%20matching%20braces/near/220060301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html#220060301">(Dec 15 2020 at 23:47)</a>:</h4>
<p>You can select <code>Thing</code>, then typing <code>{</code> should wrap it for you in braces, but aside from that I don't think LSP allows you to change that behaviour</p>



<a name="220086270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert%20matching%20braces/near/220086270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html#220086270">(Dec 16 2020 at 07:59)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> re-install the extension from source, we accidently ignored the relevant config file in the latest release</p>



<a name="220086289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert%20matching%20braces/near/220086289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html#220086289">(Dec 16 2020 at 07:59)</a>:</h4>
<p>this is handled by regexes on the client side, which is wrong</p>



<a name="220086378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert%20matching%20braces/near/220086378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html#220086378">(Dec 16 2020 at 08:00)</a>:</h4>
<p>we should implement this server-side, in principle, but neither VS Code nor LSP have APIs fro that</p>



<a name="220112672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert%20matching%20braces/near/220112672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html#220112672">(Dec 16 2020 at 13:07)</a>:</h4>
<p>Maybe we should propose something. Actually... I think we could use <code>textDocument/onTypeFormatting</code> since it sends back <code>TextEdit[]</code></p>



<a name="220127890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert%20matching%20braces/near/220127890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Auto-insert.20matching.20braces.html#220127890">(Dec 16 2020 at 15:15)</a>:</h4>
<p>In thinking about it more I think we could do this from the server side if we made <code>{</code> a trigger char for type formatting. Alternatively we could kick off a workspace edit from <code>didChange</code> but that would be more complicated.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>